package site.yunnong.atvris.admin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.yunnong.atvris.common.exception.LocalAssert;
import site.yunnong.atvris.dao.domain.User;
import site.yunnong.atvris.service.UserService;
import site.yunnong.atvris.common.dto.UserQueryParam;

import java.util.List;



/**
 * 
 *
 * @author zhangjinghao
 * @email jhzhang9102@163.com
 * @date 2021-07-09 23:45:38
 */
@RestController
@RequestMapping("common/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ResultVO list(@RequestBody UserQueryParam param){
        List<User> userList = userService.queryPage(param);

        return ResultVO.success(userList);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public ResultVO info(@PathVariable("id") Long id){
		User user = userService.queryByUuid(id);

        return ResultVO.success(user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public ResultVO save(@RequestBody User user){
        int count = userService.insert(user);
        LocalAssert.notZero(count, "保存失败");
        return ResultVO.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public ResultVO update(@RequestBody User user){
        int count = userService.update(user);
        LocalAssert.notZero(count, "修改失败");
        return ResultVO.success();
    }

}
